package com.fishery.quartz.controller;

import com.fishery.client.*;
import com.fishery.entity.Result;
import com.fishery.entity.SearchOrderConditionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * 领导仓前端控制器
 *
 * @author Ghost
 * @since 2021-2-1
 */

@RestController
@RequestMapping("/leader")
@CrossOrigin
@Api(tags = "领导仓信息管理模块")
public class LeaderController {

	@Autowired
	private BaseClient baseClient;

	@Autowired
	private ProcessingClient processingClient;

	@Autowired
	private MemberClient memberClient;

	@Autowired
	private OrderClient orderClient;

	@Autowired
	private RefrigeratoryClient refrigeratoryClient;

	@GetMapping("/base/info/{baseId}")
	@ApiOperation("获取基地的基本信息")
	public Result getBaseInfo(@PathVariable(name = "baseId", required = true)
							  @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.getBaseInfo(baseId);
	}

	@GetMapping("/base/amount/{baseId}")
	@ApiOperation("获取基地的总人数")
	public Result getMemberAmountOfBase(@PathVariable(name = "baseId", required = true)
										@ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return memberClient.pageBaseMemberCount(baseId);
	}

	@GetMapping("/pond/{baseId}")
	@ApiOperation("获取基地的池塘总数量、总面积")
	public Result getPondAmountAndAreaOfBase(@PathVariable(name = "baseId", required = true)
											 @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.getPondInfo(baseId);
	}

	@GetMapping("/ref/{baseId}")
	@ApiOperation("获取基地冷库的总数量、总面积")
	public Result getRefrigeratoryAmountAndAreaOfBase(@PathVariable(name = "baseId", required = true)
													  @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		HashMap<String, Object> map = new HashMap<>(2);
		map.put("area", refrigeratoryClient.selectAllArea(baseId).getData());
		map.put("amount", refrigeratoryClient.selectAllRefrigeratoryCount(baseId).getData());
		return Result.success().data(map);
	}


	@GetMapping("/pro/{baseId}")
	@ApiOperation("获取基地加工厂的总数量、总面积")
	public Result getProcessingFactoryAmountAndAreaOfBase(@PathVariable(name = "baseId", required = true)
														  @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return processingClient.searchFactoryMessageOfBase(baseId);
	}

	@GetMapping("/pondInfo/{baseId}")
	@ApiOperation("获取基地所有池塘的情况")
	public Result getAllPondInfoOfBase(@PathVariable(name = "baseId", required = true)
									   @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.getAllPondInfo(baseId);
	}

	@GetMapping("/base/germchit/{baseId}")
	@ApiOperation("获取基地各种种类的种苗进货量、库存量、使用量、产量信息")
	public Result getGermchitInfoOfBase(@PathVariable(name = "baseId", required = true) @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.getAmountOfVariousGermchit(baseId);
	}

	@GetMapping("/supply/{baseId}")
	@ApiOperation("获取基地投入品进货量、库存量、使用量信息")
	public Result getSupplyInfoOfBase(@PathVariable(name = "baseId", required = true) @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.searchAmountInfoOfBaseSupply(baseId);
	}

	@GetMapping("/supply/in/{baseId}")
	@ApiOperation("获取投入品的入库信息")
	public Result getSuuplyInInfoOfBase(@PathVariable(name = "baseId", required = true) @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.searchAmountInfoOfBaseSupplyIn(baseId);
	}

	@GetMapping("/supply/out/{baseId}")
	@ApiOperation("获取投入品的出库信息")
	public Result getSuuplyOutInfoOfBase(@PathVariable(name = "baseId", required = true) @ApiParam(value = "基地Id", required = true) String baseId) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return baseClient.searchAmountInfoOfBaseSupplyOut(baseId);
	}


	@PostMapping("/order")
	@ApiOperation("获取基某个时间段的订单数量、订单总额信息")
	public Result getRecentOrderOfbase(@RequestBody @ApiParam(value = "searchOrderConditionVo") SearchOrderConditionVo searchOrderConditionVo) {
		if (searchOrderConditionVo == null
				|| StringUtils.isEmpty(searchOrderConditionVo.getBaseId())) {
			return Result.error("获取失败");
		}
		return orderClient.searchSaleOrderOfBase(searchOrderConditionVo);
	}

	@GetMapping("/customer/{baseId}/{size}")
	@ApiOperation("获取基地前Size排名的大顾客（靠消费总额排名）")
	public Result getTopCustomers(@PathVariable(value = "baseId") @ApiParam(value = "基地Id", required = true) String baseId,
								  @PathVariable(value = "size") @ApiParam(value = "个数", required = true) Integer size) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("获取失败");
		}
		return orderClient.searchTopCustomerOfBase(baseId, size);
	}


}
